<template>
  <el-dialog title="卫生检查录入"
             :visible.sync="detailShow"
             :before-close="handleClose"
             width="700px"
             :close-on-click-modal="false">
    <el-form :label-position="labelPosition"
             ref="form"
             :model="form"
             :rules="rules"
             label-width="120px">
      <el-form-item label="检查人"
                    prop="checkUserName">
        <el-input v-model="form.checkUserName"
                  size="small"></el-input>
      </el-form-item>
      <el-form-item v-for="(item, index) in formData"
                    :key="index"
                    :prop="item.name"
                    :label="item.name">
        <el-input v-model.number="form[item.name]"
                  size="small"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer"
          class="dialog-footer">
      <el-button @click="preClose"
                 size="small">取 消</el-button>
      <el-button type="primary"
                 size="small"
                 @click="handleConfirm">确认</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  name: '',
  props: {
    formData: Array,
    detailShow: Boolean,
    handleClose: Function,
    rules: Object
  },
  mixins: [],
  components: {},
  data () {
    return {
      labelPosition: 'top',
      form: {
        checkUserName: ''
      }
    }
  },
  created () {
  },
  mounted () {
    this.formData.forEach(item => {
      this.form[item.name] = ''
    })
    console.log(this.rules)
  },
  methods: {
    preClose () {
      this.$refs.form.resetFields()
      this.handleClose()
    },
    handleConfirm () {
      this.$refs.form.validate(valid => {
        if (valid) {
          for (var item in this.form) {
            if (item !== 'checkUserName') {
              this.form[item] = Number.parseFloat(this.form[item].toFixed(2))
            }
          }
          this.$emit('handleConfirm', this.form)
        }
      })
    }
  }
}
</script>
<style lang='less' scoped>
</style>
